home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 117 / PC Guia 117.iso / Software / Utils / Software2 / Product11 / Setup.exe / MT-3.16-full-en_US / mt.js < prev    next >
Text File  |  2005-03-04  |  6KB  |  206 lines

  1. var ScriptURI;
  2. var ScriptBaseURI;
  3. var StaticURI;
  4.  
  5. if ((!(navigator.appVersion.indexOf('MSIE') != -1) &&
  6.       (parseInt(navigator.appVersion)==4))) {
  7.     document.write("<style type=\"text/css\">");
  8.     document.write("body { margin-top: -8px; margin-left: -8px; }"); 
  9.     document.write("</style>");
  10. }
  11.  
  12. var origWidth, origHeight;
  13. if ((navigator.appName == 'Netscape') &&
  14.     (parseInt(navigator.appVersion) == 4)) {
  15.     origWidth = innerWidth;
  16.     origHeight = innerHeight;
  17.     window.onresize = restore;
  18. }
  19.  
  20. function restore () {
  21.     if (innerWidth != origWidth || innerHeight != origHeight)
  22.         location.reload();
  23. }
  24.  
  25. function doRebuild (blogID) {
  26.     window.open(ScriptURI + '?__mode=rebuild_confirm&blog_id=' + blogID, 'rebuild', 'width=400,height=250,resizable=yes');
  27. }
  28.  
  29. function openManual (page, anchor) {
  30.     window.open(StaticURI + 'docs/mtmanual_' + page + '.html#' + anchor, 'manual', 'width=450,height=550,scrollbars=yes,status=yes,resizable=yes');
  31.     return false;
  32. }
  33.  
  34. function doRemoveItems (f, type, plural, nameRestrict) {
  35.     var base = ScriptURI + '?__mode=delete_confirm&_type=' + type;
  36.     var url = '';
  37.     var e = f.id;
  38.     if (!e) return;
  39.     if (e.value && e.checked)
  40.         url += '&id=' + e.value;
  41.     else
  42.     if (nameRestrict) {
  43.         for (i=0; i<e.length; i++)
  44.             if (e[i].checked && (e[i].name == nameRestrict))
  45.                     url += '&id=' + e[i].value;
  46.     } else {
  47.         for (i=0; i<e.length; i++)
  48.             if (e[i].checked)
  49.                     url += '&id=' + e[i].value;
  50.     }
  51.     if (!url) {
  52.         alert('You did not select any ' + plural + ' to delete.');
  53.         return false;
  54.     }
  55.     url = base + url;
  56.     window.open(url, 'confirm_delete', 'width=370,height=250,scrollbars=yes');
  57. }
  58.  
  59. function doRemoveItem (id, type) {
  60.     var url = ScriptURI;
  61.     url += '?__mode=delete_confirm&_type=' + type + '&id=' + id;
  62.     window.open(url, 'confirm_delete', 'width=370,height=250,scrollbars=yes');
  63. }
  64.  
  65. function getByID (n) {
  66.     var d = window.document;
  67.     if (d.getElementById)
  68.         return d.getElementById(n);
  69.     else if (d.all)
  70.         return d.all[n];
  71. }
  72.  
  73. var theForm;
  74. var requestSubmitted = false;
  75. function disableButton (e) {
  76.     if (!requestSubmitted) {
  77.         e.disabled = true;
  78.         theForm = e.form;
  79.         requestSubmitted = true;
  80.         setTimeout('submitIt()', 250);
  81.     } else {
  82.         return false;
  83.     }
  84. }
  85.  
  86. function submitIt () {
  87.     theForm.submit();
  88.     return false;
  89. }
  90.  
  91. function checkAndSubmit (f) {
  92.     if (requestSubmitted == true) {
  93.         return false;
  94.     } else {
  95.         requestSubmitted = true;
  96.         f.submit();
  97.         return false;
  98.     }
  99. }
  100.  
  101. function dirify (str) {
  102.     var s = str.toLowerCase();
  103.     s = s.replace(/&[^;\s]+;/g, '');
  104.     s = s.replace(/[^\w\s]/g, '');
  105.     s = s.replace(/\s+/g, '_');
  106.     return s;
  107. }
  108.  
  109. var canFormat = 0;
  110. if (document.selection)
  111.     canFormat = 1;
  112. var ua = navigator.userAgent;
  113. if (ua.indexOf('Gecko') >= 0 && ua.indexOf('Safari') < 0)
  114.     canFormat = 1;
  115.  
  116. function getSelected (e) {
  117.     if (document.selection) {
  118.         e.focus();
  119.         var range = document.selection.createRange();
  120.         return range.text;
  121.     } else {
  122.         var length = e.textLength;
  123.         var start = e.selectionStart;
  124.         var end = e.selectionEnd;
  125.         if (end == 1 || end == 2) end = length;
  126.         return e.value.substring(start, end);
  127.     }
  128. }
  129.  
  130. function setSelection (e, v) {
  131.     if (document.selection) {
  132.         e.focus();
  133.         var range = document.selection.createRange();
  134.         range.text = v;
  135.     } else {
  136.         var length = e.textLength;
  137.         var start = e.selectionStart;
  138.         var end = e.selectionEnd;
  139.         if (end == 1 || end == 2) end = length;
  140.         e.value = e.value.substring(0, start) + v + e.value.substr(end, length);
  141.         e.selectionStart = start + v.length;
  142.         e.selectionEnd = start + v.length;
  143.     }
  144.     e.focus();
  145. }
  146.  
  147. function formatStr (e, v) {
  148.     if (!canFormat) return;
  149.     var str = getSelected(e);
  150.     if (!str) return;
  151.     setSelection(e, '<' + v + '>' + str + '</' + v + '>');
  152.     return false;
  153. }
  154.  
  155. function mtShortCuts(e) {
  156.     e = e || event;
  157.     if (!e || (!e.ctrlKey)) return;
  158.     /* we have to add 64 to keyCode since the user hit a control key */
  159.     var code = (e.keyCode) ? (e.keyCode + 64) :
  160.                ((e.which) ? e.which : 0);
  161.     var ch = String.fromCharCode(code);
  162.     el = e.target || e.srcElement;
  163.     if (el.nodeType == 3) el = el.parentNode; // Safari bug
  164.     if (ch == 'A') insertLink(el, false);
  165.     if (ch == 'B') formatStr(el, 'strong');
  166.     if (ch == 'I') formatStr(el, 'em');
  167.     if (ch == 'U') formatStr(el, 'u');
  168. }
  169.  
  170. function insertLink (e, isMail) {
  171.     if (!canFormat) return;
  172.     var str = getSelected(e);
  173.     var link = '';
  174.     if (!isMail) {
  175.         if (str.match(/^https?:/)) {
  176.             link = str;
  177.         } else if (str.match(/^(\w+\.)+\w{2,5}\/?/)) {
  178.             link = 'http://' + str;
  179.         } else if (str.match(/ /)) {
  180.             link = 'http://';
  181.         } else {
  182.             link = 'http://' + str;
  183.         }
  184.     } else {
  185.         if (str.match(/@/)) {
  186.             link = str;
  187.         }
  188.     }
  189.     var my_link = prompt(isMail ? 'Enter email address:' : 'Enter URL:', link);
  190.     if (my_link != null) {
  191.          if (str == '') str = my_link;
  192.          if (isMail) my_link = 'mailto:' + my_link;
  193.         setSelection(e, '<a href="' + my_link + '">' + str + '</a>');
  194.     }
  195.     return false;
  196. }
  197.  
  198. function doCheckAll (f, v) {
  199.     var e = f.id;
  200.     if (e.value)
  201.         e.checked = v;
  202.     else
  203.         for (i=0; i<e.length; i++) 
  204.             e[i].checked = v;
  205. }
  206.